package com.itheima.e_row;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/row")
public class RowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求方式
        String method = req.getMethod();
        System.out.println("请求方式为："+method);
        //获取请求项目的项目名称
        String contextPath = req.getContextPath();
        System.out.println(""+contextPath);
        //获取请求者的ip地址
        String remoteAddr = req.getRemoteAddr();
        System.out.println("请求者的ip地址为："+remoteAddr);
        //获取请求者的端口号
        int localPort = req.getLocalPort();
        System.out.println("请求的端口号为："+localPort);
        //获取请求资源
        String requestURI = req.getRequestURI();
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("URI:"+requestURI);
        System.out.println("URL:"+requestURL);
        //获取请求协议和版本
        String protocol = req.getProtocol();
        System.out.println("请求的协议和版本："+protocol);
        //获取请求携带的参数，以一个字符串的形式返回
        String queryString = req.getQueryString();
        System.out.println("请求的参数为："+queryString);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
